#include "MainForm.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

MainForm::MainForm(void)
{
}

MainForm::~MainForm(void)
{
}

bool
MainForm::Initialize()
{
	// Construct an XML form
	Construct(L"IDF_MAINFORM");

	return true;
}

result
MainForm::OnInitializing(void)
{
	result r = E_SUCCESS;

	__pButtonNone = static_cast<Button *>(GetControl(L"NONE"));
	if (__pButtonNone != null)
	{
		__pButtonNone->SetActionId(ID_BUTTON_NONE);
		__pButtonNone->AddActionEventListener(*this);
	}
	__pButtonOk = static_cast<Button *>(GetControl(L"OK_BUTTON"));
		if (__pButtonOk != null)
		{
			__pButtonOk->SetActionId(ID_BUTTON_OK);
			__pButtonOk->AddActionEventListener(*this);
		}
	__pButtonCancel = static_cast<Button *>(GetControl(L"CANCEL_BUTTON"));
		if (__pButtonCancel != null)
		{
			__pButtonCancel->SetActionId(ID_BUTTON_CANCEL);
			__pButtonCancel->AddActionEventListener(*this);
		}
	__pButtonOkCancel = static_cast<Button *>(GetControl(L"OKCANCEL"));
		if (__pButtonOkCancel != null)
		{
			__pButtonOkCancel->SetActionId(ID_BUTTON_OKCANCEL);
			__pButtonOkCancel->AddActionEventListener(*this);
		}
	__pButtonYesNo = static_cast<Button *>(GetControl(L"YESNO_BUTTON"));
		if (__pButtonYesNo != null)
		{
			__pButtonYesNo->SetActionId(ID_BUTTON_YESNO);
			__pButtonYesNo->AddActionEventListener(*this);
		}
	__pButtonYesNoCancel = static_cast<Button *>(GetControl(L"YESNOCANCEL"));
		if (__pButtonYesNoCancel != null)
		{
			__pButtonYesNoCancel->SetActionId(ID_BUTTON_YESNOCANCEL);
			__pButtonYesNoCancel->AddActionEventListener(*this);
		}
	__pButtonAbortRetryIgnore = static_cast<Button *>(GetControl(L"ABORTRETRYIGNORE"));
		if (__pButtonAbortRetryIgnore != null)
		{
			__pButtonAbortRetryIgnore->SetActionId(ID_BUTTON_ABORTRETRYIGNORE);
			__pButtonAbortRetryIgnore->AddActionEventListener(*this);
		}
	__pButtonCancelTryContinue = static_cast<Button *>(GetControl(L"CANCELTRYCONTINUE"));
		if (__pButtonCancelTryContinue != null)
		{
			__pButtonCancelTryContinue->SetActionId(ID_BUTTON_CANCELTRYCONTINUE);
			__pButtonCancelTryContinue->AddActionEventListener(*this);
		}
	__pButtonRetryCancel = static_cast<Button *>(GetControl(L"RETRYCANCEL"));
		if (__pButtonRetryCancel != null)
		{
			__pButtonRetryCancel->SetActionId(ID_BUTTON_RETRYCANCEL);
			__pButtonRetryCancel->AddActionEventListener(*this);
		}

	return r;
}

result
MainForm::OnTerminating(void)
{
	result r = E_SUCCESS;

	// TODO: Add your termination code here

	return r;
}

void
MainForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	switch(actionId)
	{
	case ID_BUTTON_NONE:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: NONE",
							 MSGBOX_STYLE_NONE, 1000);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			AppLog("none\n");
		}
		break;
	case ID_BUTTON_OK:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: OK",
							 MSGBOX_STYLE_OK, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			if (modalResult == MSGBOX_RESULT_OK)
				AppLog("OK clicked\n");
		}
		break;
	case ID_BUTTON_CANCEL:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: CANCEL",
							 MSGBOX_STYLE_CANCEL, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			if (modalResult == MSGBOX_RESULT_CANCEL)
				AppLog("cancel clicked\n");
		}
		break;
	case ID_BUTTON_OKCANCEL:
		{
			MessageBox msgbox;
			msgbox.Construct("Buntetese: szetpixelezes", "style: OKCANCEL",
							 MSGBOX_STYLE_OKCANCEL, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			if (modalResult == MSGBOX_RESULT_OK)
				AppLog("OK clicked\n");
			else
				AppLog("cancel clicked\n");
		}
		break;
	case ID_BUTTON_YESNO:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: NONE",
							 MSGBOX_STYLE_YESNO, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			if (modalResult == MSGBOX_RESULT_YES)
				AppLog("yes clicked\n");
			else
				AppLog("no clicked\n");
		}
		break;
	case ID_BUTTON_YESNOCANCEL:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: YESNOCANCEL",
							 MSGBOX_STYLE_YESNO, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			switch (modalResult)
			{
				case MSGBOX_RESULT_YES:
					AppLog("yes clicked\n");
					break;
				case MSGBOX_RESULT_NO:
					AppLog("no clicked\n");
					break;
				default:
					AppLog("cancel clicked\n");
					break;
			}
		}
		break;
	case ID_BUTTON_ABORTRETRYIGNORE:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: ABORTRETRYIGNORE",
							 MSGBOX_STYLE_ABORTRETRYIGNORE, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			switch (modalResult)
			{
				case MSGBOX_RESULT_ABORT:
					AppLog("abort clicked\n");
					break;
				case MSGBOX_RESULT_RETRY:
					AppLog("retry clicked\n");
					break;
				default:
					AppLog("ignore clicked\n");
					break;
			}
		}
		break;
	case ID_BUTTON_CANCELTRYCONTINUE:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: CANCELTRYCONTINUE",
							 MSGBOX_STYLE_CANCELTRYCONTINUE, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			switch (modalResult)
			{
				case MSGBOX_RESULT_CANCEL:
					AppLog("cancel clicked\n");
					break;
				case MSGBOX_RESULT_TRY:
					AppLog("try clicked\n");
					break;
				default:
					AppLog("continue clicked\n");
					break;
			}
		}
		break;
	case ID_BUTTON_RETRYCANCEL:
		{
			MessageBox msgbox;
			msgbox.Construct("messagebox", "style: RETRYCANCEL",
							 MSGBOX_STYLE_RETRYCANCEL, 0);
			int modalResult = 0;
			msgbox.ShowAndWait(modalResult);
			switch (modalResult)
			{
				case MSGBOX_RESULT_CANCEL:
					AppLog("cancel clicked\n");
					break;
				case MSGBOX_RESULT_RETRY:
					AppLog("retry clicked\n");
					break;
				default:
					break;
			}
		}
		break;
	default:
		break;
	}
}

